//
//  DBVC.m
//  UHealth
//
//  Created by gjtxz on 15/1/10.
//  Copyright (c) 2015年 gjtx. All rights reserved.
//

#import "DBVC.h"
#import "DBManage.h"
#import "NSString+BloodSugar.h"

@interface DBVC ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong)NSMutableArray  *dbArr;
@property (nonatomic,strong)UITableView     *dbTable;

@end

@implementation DBVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSString *str = [NSString stringWithFormat:@"%@ = '%@'",kSensorID,_sensorID];
    
    _dbArr = [[DBManage sharedManager] queryDataFromTable:kBloodSugarTable andConditions:str];
    _dbTable = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _dbTable.dataSource = self;
    _dbTable.delegate = self;
    [self.view addSubview:_dbTable];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dbArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID =@"cellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    
    BSDataObj *b = _dbArr[indexPath.row];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%d %d",b.currentIndex,b.currentValue];
    
    return cell;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
